export const fieldMapMixins = {
    data() {
        return {

        }
    },
    mounted() {

    },

    methods: {
        handleRefMap(mode, data, refmap) {
            const mapField = []
            let mapObjectStr = this.$store.state.ref_toobject
            console.log("mapObjectStr",mapObjectStr)
            console.log("refmap",refmap)
            
            for (let key in refmap) {
                // if (key.indexOf('_ref.') == -1) {
                //     const fieldArr = key.split('_')
                //     mapField.push(fieldArr[1])
                // }
                if (key.indexOf(`${mapObjectStr}_`) !== -1) {
                    const fieldArr = key.split(/_(.*)$/, 2);
                    mapField.push(fieldArr[1])
                }
            }
        

            if (mode === 'headdata') {
                for (let i = 0; i < data.length; i++) {
                    for (let j = 0; j < data[i].groupvalue.length; j++) {
                        if (mapField.indexOf(data[i].groupvalue[j].sField) !== -1) {
                            switch (data[i].groupvalue[j].sUIType) {
                                case 'ref':
                                    data[i].groupvalue[j].value = refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}_ref`] || refmap[`${data[i].groupvalue[j].sField}_ref`]
                                    data[i].groupvalue[j].valuehidden = refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}`] || refmap[`${data[i].groupvalue[j].sField}`]
                                    break
                                case 'enum':
                                    data[i].groupvalue[j].value = refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}_enum`] || refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}_ref`]
                                    data[i].groupvalue[j].valuehidden = refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}`]
                                    break
                                case 'bool':
                                    data[i].groupvalue[j].value = refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}`] == '1' ? '是' : '否'
                                    break
                                default:
                                    data[i].groupvalue[j].value = refmap[`${mapObjectStr}_${data[i].groupvalue[j].sField}`]
                                    break
                            }
                        }
                    }
                }
            }
            if (mode === 'bodydata') {
                for (let i = 0; i < data.length; i++) {
                    if (mapField.indexOf(data[i].sField) !== -1) {
                        switch (data[i].sUIType) {
                            case 'ref':
                                data[i].value = refmap[`${mapObjectStr}_${data[i].sField}_ref`]
                                data[i].valuehidden = refmap[`${mapObjectStr}_${data[i].sField}`]
                                break
                            case 'enum':
                                data[i].value = refmap[`${mapObjectStr}_${data[i].sField}_enum`]
                                data[i].valuehidden = refmap[`${mapObjectStr}_${data[i].sField}`]
                                break
                            case 'bool':
                                data[i].value = refmap[`${mapObjectStr}_${data[i].sField}`] === '1' ? '是' : '否'
                                break
                            default:
                                data[i].value = refmap[`${mapObjectStr}_${data[i].sField}`]
                                break
                        }
                    }
                }
            }
        }

    },
    activated() {


        // console.log("this.clickindexName%%%%%%",this.clickindexName)
        // console.log("this.clickindex%%%%%%",this.clickindex)
        console.log("&&&&&&&","ref_show(sname)没有配置不走映射")
        if (this.$store.state.ref_show !== '') {
            this.clickmodel.value = this.$store.state.ref_show
            console.log("%%%%",this.$store.state.ref_map)

            this.clickmodel.value = this.$store.state.ref_show
            this.clickmodel.valuehidden = this.$store.state.ref_id
            this.clickmodel.errormsg = ''

            if (this.$store.state.ref_map) {
                if (this.clickfrom === 'headdata') {
                    this.handleRefMap('headdata', this.jsondata.head, this.$store.state.ref_map)
                } else if (this.clickfrom === 'bodydata') {
                    this.handleRefMap('bodydata', this.jsondata.bodydata[this.clickindexName][this.clickindex], this.$store.state.ref_map)
                }
            }

            this.clickmodel = {}
            this.clickindex = 0
            this.clickindexName = ''
            this.clickfrom = ''
            this.$store.commit('clearRef')


        }
    }

}
